<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../../config.inc.php");
session_start();
$_LangPath = "comparesupplewagerList";
if($_data["AllPowers"] != "Y"){
	include_once(__Admin_Path."/logincheck_op.php");
}else{
	include_once(__DBConnect_File);
}
include_once(__Language_Path."/selectlanguage_admin.php");
include_once(__Modules_Path."/BetType.lib.php");
include_once(__Modules_Path."/Lotto.lib.php");
include_once(__Modules_Path."/WagerForm.lib.php");
include_once(__Modules_Path."/ChangeTime.lib.php");
include_once(__Common_Path."/SysParam.inc.php");

$arrPower = CheckUsePower("comparesupplewagerlist");
if($arrPower === false)ErrMsgOutputHTML("Error", "", 1);

if($_data["payupdate"] == "")$_data["payupdate"] = date("Y-m-d");
$strSQL = "";

$strSQL = "select a.ID, a.LottoID, b.BetDate, b.BetTime, a.Bet_Type, b.Content, a.MemID, a.MemStake, a.MemResult, a.isPayOff, b.MemAccount, b.OneStake, b.SuppleID from `bet_BetList` a, `bet_BetListContent` b where a.ID = b.ID and a.PayupDate = '".$_data["payupdate"]."' and b.MemAccount = '".$_KSysParam[SuppleReAccount]."' order by a.ID";

$intTolStake = 0;
$intTolResult = 0;
if($strSQL != ""){
	//print $strSQL;
	if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
		$GLOBALS["errormessage"] = "Find Wager Data Error!";
		$GLOBALS["errorhidden"] = "SQL: ".$strSQL.", \nError: ".PMA_mysql_error($$_Conn).", \nLine: ".__LINE__.", \nPage: ".__FILE__;
		ErrMsgOutputHTML("Error", "", 1);
	}
	$arrBID = array();
	$arrBet = array();
	$arrSuppleID = array();
	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrBet[$Rows -> ID]["BetDate"] = DateForm($Rows -> BetDate, $Rows -> BetTime, "Y-m-d");
		$arrBet[$Rows -> ID]["BetTime"] = TimeForm($Rows -> BetDate, $Rows -> BetTime, "H:i:s");
		$arrBet[$Rows -> ID]["Bet_Type"] = $Rows -> Bet_Type;
		$arrBet[$Rows -> ID]["ScoreID"] = $Rows -> ScoreID;
		$arrBet[$Rows -> ID]["Score"] = $Rows -> Score;
		$arrBet[$Rows -> ID]["GambleID"] = $Rows -> GambleID;
		$arrBet[$Rows -> ID]["Content"] = $Rows -> Content;
		$arrBet[$Rows -> ID]["MemID"] = $Rows -> MemID;
		$arrBet[$Rows -> ID]["MemStake"] = $Rows -> MemStake;
		$arrBet[$Rows -> ID]["OneStake"] = $Rows -> OneStake;
		$arrBet[$Rows -> ID]["MemResult"] = $Rows -> MemResult;
		$arrBet[$Rows -> ID]["isPayOff"] = $Rows -> isPayOff;
		$arrBet[$Rows -> ID]["MemAccount"] = $Rows -> MemAccount;
		$arrBet[$Rows -> ID]["LottoID"] = $Rows -> LottoID;
		$arrSuppleID[] = $Rows -> ID;
		$arrBID[] = $Rows -> ID;
	}
	if(sizeof($arrSuppleID) > 0){
		$ch = curl_init ();
		curl_setopt($ch,CURLOPT_URL, "http://".$_KSysParam[SuppleIP]."/k_admin/Supplement/index.php?op=sendSuppleWagerList&suppleid=".join(",", $arrSuppleID)."&acc=".$_KSysParam[SuppleAccount]."&payupdate=".$_data["payupdate"]);
		//print "http://".$_KSysParam[SuppleIP]."/k_admin/Supplement/index.php?op=sendSuppleWagerList&suppleid=".join(",", $arrSuppleID)."&acc=".$_KSysParam[SuppleAccount]."&payupdate=".$_data["payupdate"];
		curl_setopt ($ch, CURLOPT_VERBOSE, 1);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt ($ch, CURLOPT_HEADER, 0);
		curl_setopt ($ch, CURLOPT_HTTPHEADER, array(
			"Accept:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-shockwave-flash, */*",
			"User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
			"Host:".$_KSysParam[SuppleUrl],
			"Connection:Keep-Alive"));
		$strCont = curl_exec ($ch);
		//print $strCont."sss";
		curl_close ($ch);
		if(preg_match("/arrWager/", $strCont)){
			eval($strCont);
		}else{
			$arrWager = array();
		}
	}
}

?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="/css/backend.css" type="text/css">
<script language="JavaScript1.2" type="text/javascript" src="/inc/admin_envirset.js"></script>
<script language="JavaScript">
<!--
	var strRowClassName = ",datarow,";
	function SelectAllBet(isOff){
		with(document.beMemberFrm){
			if(arrBID.length){
				for(var i = 0; i < arrBID.length; i++)arrBID[i].checked = true;
			}else{
				arrBID.checked = true;
			}
		}
	}

	function arrAccept(isAccept){
		var arrBIDs = new Array(), j = 0, arrParlays = new Array();
		with(document.beMemberFrm){
			if(arrBID.length > 0){
				for(var i = 0; i < arrBID.length; i++){
					if(arrBID[i].checked){
						arrBIDs[j] = arrBID[i].value;
						j++
					}
				}
			}else{
				if(arrBID.checked){
					arrBIDs[j] = arrBID.value;
					j++
				}
			}

			if(document.getElementById("Parlay")){
				if(Parlay.length > 0){
					for(var i = 0; i < Parlay.length; i++){
						if(Parlay[i].checked){
							arrParlays[j] = Parlay[i].value;
							j++
						}
					}
				}else{
					if(document.getElementById("Parlay").checked){
						arrParlays[j] = Parlay.value;
						j++
					}
				}
			}
		}
		document.AcceptForm.isAccept.value = (isAccept == 1)?1:0;

		if(arrBIDs.length > 0 || arrParlays.length > 0){
			if(arrBIDs.length > 0)document.AcceptForm.BID.value = arrBIDs.join(",");
			if(arrParlays.length > 0)document.AcceptForm.arrParlay.value = arrParlays.join(",");
			if(confirm("Are you "+((isAccept == 1)?"":" ' not ' ")+"sure to accept these betting tickets?")){
				document.AcceptForm.submit();
			}
		}
	}

	function ShowLog(WagerID){
		window.open("ShowLog.php?WagerID="+WagerID,"ShowLogWindow","toolbar=no,width=540,height=400,top=0,left=0,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
	}
//-->
</script>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #F7F7F7;
	font-size: 12px
}
.BetID{
	color: #FF0000;
	font-weight: 700;
}
//-->
</style>
</head>
<body>
<form action="<?php print $_SERVER["PHP_SELF"];?>" method="Get" name="beMemberFrm">
<input type="hidden" name="op" value="ChangeRiskBet">

<fieldset style="width: 450px">
	<legend>Search</legend>
	<table style="width: 400px; font-size: 12px">
	<tr>
		<td align="right">Date</td>
		<td align="left"><input type="text" name="payupdate" value="<?php print $_data["payupdate"];?>" size="20" class="input_text"><input type="submit" value="Go" class="submit"></td>
	</tr>
	</table>
</fieldset>
<br /><br />
<!--Content Start//-->
<table class="content_b">
<tr>
<td valign="center" style="font-weight: 700; font-size: 16px"><?php print $_strCompareSuppleWagerList["Title"]?></td>
<td valign="top" align="right">&nbsp;</td></tr>
<tr>
<td valign="top" colspan="2">
<table border="0" cellpadding="0" cellspacing="0" bgcolor="#0054E3F"><tr><td>
<table width="990" border="0" cellpadding="3" cellspacing="1" style="font-size: 12px">
<tr bgcolor="#7A96E9" align="center">
<td width="40"><?php print $_strCompareSuppleWagerList["Select"];?></td>
<td width="120"><?php print $_strCompareSuppleWagerList["TimeTicketNo"];?></td>
<td width="60"><?php print $_strCompareSuppleWagerList["SuppleID"];?></td>
<td width="80"><?php print $_strCompareSuppleWagerList["SuppleMember"];?></td>
<td width="80"><?php print $_strCompareSuppleWagerList["Member"];?></td>
<td width="70"><?php print $_strCompareSuppleWagerList["Type"];?></td>
<td width="220"><?php print $_strCompareSuppleWagerList["Content"];?></td>
<td width="80"><?php print $_strCompareSuppleWagerList["Stake"];?></td>
<td width="80"><?php print $_strCompareSuppleWagerList["Result"];?></td>
<td width="80"><?php print $_strCompareSuppleWagerList["Status"];?></td>
<td width="80"><?php print $_strCompareSuppleWagerList["SuppleStatus"];?></td>
</tr>
<?php
$intTolWager = 0;
while(list($k, $v) = each($arrBet)){
	if(!is_array($arrWager[$k]) && $v["isPayOff"] == -2)continue;
	$BetNo = abs($v["isPayOff"]);
	if($v["isPayOff"] >= 0){
		$intTolStake += $v["MemStake"];
		$intTolResult += $v["MemResult"];
	}
	$intTolWager += 1;
?>
<tr class="datarow" bgcolor="#FFFFFF"><label for="isArray<?php print $k;?>">
<td align="center">
<!--<?php if(ereg("all|supple", $arrPower[1]) || $v["MemAccount"] != $_KSysParam[SuppleReAccount]){ ?><input type="checkbox" name="arrBID" value="<?php print $k;?>" id="isArray<?php print $k;?>"><?php } ?>//--></td>
<td align="left"><?php print $v["BetDate"];?>&nbsp;&nbsp;<?php print $v["BetTime"];?><br /><a class="BetID"><?php print $k;?></a></td>
<td align="left" class="BetID"><?php print $arrWager[$k][0];?></td>
<td align="left"><?php print $_KSysParam[SuppleAccount];?></td>
<td align="left"><?php print $v["MemAccount"];?></td>
<td align="right"><?php print $_arrBet_Type[$v["Bet_Type"]];?></td>
<td align="left"><?php print WagerFormTrans($v["LottoID"], $v["Bet_Type"], $v["Content"]);?></td>
<td align="right"><?php
	if($v["Bet_Type"] >= 7 && $v["Bet_Type"] <= 11 && !empty($v["OneStake"])){
		if($v["MemStake"] / $v["OneStake"] > 1)print (string)$v["OneStake"]." x ".(string)round($v["MemStake"] / $v["OneStake"])."<br /><br />";
	}
	print $v["MemStake"];
?></td>
<td align="right"><?php print $v["MemResult"];?></td>
<td align="center"><?php
	switch($v["isPayOff"]){
		case -2:
			print "<b style=\"color:#FF0000\">XX</b>";
			break;
		case -1:
			print "<b style=\"color:#FF0000\">X</b>";
			break;
		default:
			print "Complete";
			break;
	}
?></td>
<td align="center"><?php
	switch($arrWager[$k][1]){
		case -1:
			print "<b style=\"color:#FF0000\">".$_strCompareSuppleWagerList["NotAccept"]."</b>";
			break;
		case 0:
			print $_strCompareSuppleWagerList["Accept"];
			break;
	}
?></td>
</label></tr>
<?php
}  //while(list($k, $v) = each($arrBet))//
?>
<tr bgcolor="#FFFFFF" align="right">
<td colspan="7"><?php print $_strCompareSuppleWagerList["Total"];?></td>
<td><?php print $intTolStake;?></td>
<td><?php print $intTolResult;?></td>
<td><?php print $intTolWager;?></td>
<td>&nbsp;</td>
</tr>
</table>
</td></tr>
</table>
</td>
</tr>
</table>
<!--Content End//-->
<!--<input type="button" value="<?php print $_strCompareSuppleWagerList["SelectAll"];//全部選取?>" onclick="SelectAllBet(0)" class="submit">
<input type="reset" value="<?php print $_strCompareSuppleWagerList["SelectNo"];//全部取消?>" class="submit">//-->
</td>
</tr>
</table>
</form>
</body>
</html>
<?php @mysql_close($$_Conn); ?>